import 'package:flutter/material.dart';

class ListenerPage extends StatefulWidget {
  @override
  _ListenerPageState createState() => _ListenerPageState();
}

class _ListenerPageState extends State<ListenerPage> {
  Offset _position = Offset.zero;
  String _eventStatus = 'No Event';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Listener Demo')),
      body: Center(
        child: Listener(
          onPointerDown: (PointerDownEvent event) {
            setState(() {
              _position = event.localPosition;
              _eventStatus = 'Pointer Down';
            });
          },
          onPointerMove: (PointerMoveEvent event) {
            setState(() {
              _position = event.localPosition;
              _eventStatus = 'Pointer Move';
            });
          },
          onPointerUp: (PointerUpEvent event) {
            setState(() {
              _position = event.localPosition;
              _eventStatus = 'Pointer Up';
            });
          },
          onPointerCancel: (PointerCancelEvent event) {
            setState(() {
              _eventStatus = 'Pointer Cancel';
            });
          },
          child: Container(
            alignment: Alignment.center,
            width: 300,
            height: 300,
            color: Colors.blue.withOpacity(0.3),
            child: Center(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    'Position: (${_position.dx.toStringAsFixed(1)}, ${_position.dy.toStringAsFixed(1)})',
                    style: TextStyle(fontSize: 20, color: Colors.white),
                  ),
                  SizedBox(height: 10),
                  Text(
                    'Event: $_eventStatus',
                    style: TextStyle(fontSize: 16, color: Colors.white),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}